using System;
using System.Collections.Generic;
using System.Text;
using Deepcode.Flux.Core.Systems.Security;

namespace Deepcode.Flux.Core.Services.Security
{
	/// <summary>
	/// This class is instantiated into the session of the currently authenticated user.
	/// This class holds all of the information concerning a particular user.
	/// </summary>
	public class AdministrationSecuritySession
	{
		private int _PK_ID = -1;
		private string _Identity = "";
		private string _Email = "";
		private string _NT_Username = "";
		private string _RealName = "";
		private bool _IsSuperUser = false;
		private AdministrationGroup[] _Groups = null;
		private string[] _Permissions = null;

		/// <summary>
		/// Get/Sets the unique ID of the authenticated user
		/// </summary>
		public int PK_ID { get { return _PK_ID; } set { _PK_ID = value; } }
		/// <summary>
		/// Get/Sets the identity of the user - taken from the HttpContext.User.Identity.Name field
		/// </summary>
		public string Identity { get { return _Identity; } set { _Identity = value; } }
		/// <summary>
		/// Get/Set the email address of the user
		/// </summary>
		public string Email { get { return _Email; } set { _Email = value; } }
		/// <summary>
		/// Get/Set the NT Authentication name of the user if Windows authentication is used
		/// </summary>
		public string NT_Username { get { return _NT_Username; } set { _NT_Username = value; } }
		/// <summary>
		/// Get/Set the real name of the user
		/// </summary>
		public string RealName { get { return _RealName; } set { _RealName = value; } }
		/// <summary>
		/// Get/Set whether the user is a super user or not (bypass all security)
		/// </summary>
		public bool IsSuperUser { get { return _IsSuperUser; } set { _IsSuperUser = value; } }
		/// <summary>
		/// Array of administration groups that this user is a member of
		/// </summary>
		public AdministrationGroup[] Groups { get { return _Groups; } set { _Groups = value; } }
		/// <summary>
		/// Returns a CSV list of the group ID's for this user
		/// </summary>
		public String GroupsCSV
		{
			get
			{
				string res = "";
				foreach (AdministrationGroup g in Groups)
				{
					if( res != "" ) res += ",";
					res += g.PK_ID;
				}
				return res;
			}
		}
		
		/// <summary>
		/// Array of permission codes that this user has as a result of their group memberships
		/// </summary>
		public string[] Permissions { get { return _Permissions; } set { _Permissions = value; } }
	}
}
